package com.hbnu.personaldiaryweb.service;

import com.hbnu.personaldiaryweb.mapper.UsersMapper;
import com.hbnu.personaldiaryweb.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService implements UsersMapper {

    //注明一个安装接口
    @Autowired
    UsersMapper usersMapper;

    // 验证用户名和密码
    public boolean validateUser(String username, String password) {
        User user = usersMapper.getByName(username);
        if (user != null && user.getPassword().equals(password)) {
            return true; // 用户名和密码匹配
        }
        return false; // 用户名或密码错误
    }





    @Override
    public int insertUser(User user) {
        return this.usersMapper.insertUser(user);
    }

    @Override
    public User getByName(String username) {
        return this.usersMapper.getByName(username);
    }

    @Override
    public List<User> getAllUsers() {
        return this.usersMapper.getAllUsers();
    }

    @Override
    public int updateUser(User user) {
        return this.updateUser(user);
    }

    @Override
    public int deleteUserById(String id) {
        return this.deleteUserById(id);
    }
}











